Programming languages provide functions to allocate memory space for a variable. The size of the allocated memory may be determined statically during compilation of the program code, or dynamically during execution of the code. The variable may belong to a certain type that is available in the programming language. For example, the variable may be a structure type in C programming language that may further include members within the structure. The memory space of the variable may be allocated on a heap or a stack. A heap is a tree-type data structure that satisfies the heap property. A stack is a linear list in which all additions and deletions are restricted to one end of the list (such as the top of the list). The structure that is allocated on a stack may have the advantages of being thread-safe and having automatic resource clean-up determined by a function scope. The clean-up may include destantiation of the structure.
However, the trade-off for allocating memory space on the stack is that the members of a structure variable may need to be made public. Although certain programming languages (such as C++) may provide keyword access to these members so that the access to these members is limited to keyword holders, any change to this size (which needs to be made public), breaks the encapsulation provided by an Application Binary Interface (ABI). The ABI is the interface between two program modules at the machine code level.
One exemplary implementation of allocating the structure on a stack is the alloca( ) function in certain installations of software environments. While alloca( ) may circumvent some of the problems associated with allocating memory on a stack, implementations of alloca( ) do not guarantee dynamic stack-based memory allocation because, although alloca( ) appears to be a function, it is sometimes handled by the compiler in certain implementations. This may cause stack overflows and difficulties in debugging. Further, the use of alloca( ) allocations is limited to a single scope context.